﻿@using Abp.MultiTenancy
@using Abp.Timing
@using MVlog.Authorization
@using MVlog.Chat.SignalR
@using MVlog.Editions
@using MVlog.Features
@using MVlog.Web.Areas.AppAreaName.Models.Layout
@model HeaderViewModel
@{
    Layout = null;
}
<div class="page-header-inner">
    <div class="page-logo">
        <a href="@Url.Action("Index", "Home", new {area = string.Empty})" target="_blank">
            <img id="AppLogo" src="@Model.GetLogoUrl(ApplicationPath)" alt="logo" class="logo-default" width="168" height="33" />
        </a>
        <div class="menu-toggler sidebar-toggler">
            <!-- DOC: Remove the above "hide" to enable the sidebar toggler button on header -->
        </div>
    </div>
    <a href="javascript:;" class="menu-toggler responsive-toggler" data-toggle="collapse" data-target=".navbar-collapse">
    </a>
    <div class="page-top">
        <div class="top-menu">
            <ul class="nav navbar-nav pull-right">

                @if (Model.Languages.Count > 1)
                {
                    <li class="dropdown dropdown-language">
                        <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                            <i class="@Model.CurrentLanguage.Icon"></i>
                            <span class="langname">
                                @Model.CurrentLanguage.DisplayName
                            </span>
                            <i class="fa fa-angle-down"></i>
                        </a>
                        <ul class="dropdown-menu">
                            @foreach (var language in Model.Languages.Where(language => language.Name != Model.CurrentLanguage.Name))
                            {
                                <li>
                                    <a href="~/AbpLocalization/ChangeCulture?cultureName=@language.Name&returnUrl=@Context.Request.Path" href="#">
                                        <i class="@language.Icon"></i> @language.DisplayName
                                    </a>
                                </li>
                            }
                        </ul>
                    </li>
                }

                <!-- BEGIN NOTIFICATION DROPDOWN -->
                <!-- DOC: Apply "dropdown-dark" class after below "dropdown-extended" to change the dropdown styte -->
                <li class="dropdown dropdown-extended dropdown-notification dropdown-dark" id="header_notification_bar">

                </li>
                <!-- END NOTIFICATION DROPDOWN -->

                <li class="separator hide"> </li>

                <!-- DOC: Apply "dropdown-dark" class after below "dropdown-extended" to change the dropdown styte -->
                <li class="dropdown dropdown-user dropdown-dark">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true" title="@(Model.IsImpersonatedLogin ? L("YouCanBackToYourAccount") : "")">
                        <span class="username username-hide-on-mobile">
                            @if (Model.IsImpersonatedLogin)
                            {
                                <i class="icon-action-undo font-red-sunglo"></i>
                            }
                            @Html.Raw(Model.GetShownLoginName())
                        </span>
                        <img id="HeaderProfilePicture" alt="" class="img-circle" src="@Url.Action("GetProfilePicture", "Profile", new {area = string.Empty})?t=@Clock.Now.Ticks.ToString()" />
                    </a>
                    <ul class="dropdown-menu dropdown-menu-default">
                        @if (Model.IsImpersonatedLogin)
                        {
                            <li>
                                <a id="UserProfileBackToMyAccountButton" href="#"><i class="icon-action-undo"></i> <strong>@L("BackToMyAccount")</strong></a>
                            </li>
                            <li class="divider"></li>
                        }
                        <li class="dropdown-submenu">
                            <a class="open-left" href=""><i class="icon-link"></i> @L("LinkedAccounts")</a>
                            <ul id="RecentlyUsedLinkedUsers" class="dropdown-menu" style=""></ul>
                        </li>
                        <li>
                            <a id="UserProfileChangePasswordLink" href="#"><i class="icon-key"></i> @L("ChangePassword")</a>
                        </li>
                        <li>
                            <a id="ShowLoginAttemptsLink" href="#"><i class="icon-shield"></i> @L("LoginAttempts")</a>
                        </li>
                        <li>
                            <a id="UserProfileChangePictureLink" href="#"><i class="icon-user"></i> @L("ChangeProfilePicture")</a>
                        </li>
                        <li>
                            <a id="UserProfileMySettingsLink" href="#"><i class="icon-settings"></i> @L("MySettings")</a>
                        </li>
                        <li class="divider"></li>
                        <li>
                            <a href="@Url.Action("Logout", "Account", new {area = string.Empty})"><i class="icon-logout"></i> @L("Logout")</a>
                        </li>
                    </ul>
                </li>

                @if (SignalRFeature.IsAvailable && (AbpSession.MultiTenancySide == MultiTenancySides.Host || IsFeatureEnabled(AppFeatures.ChatFeature)))
                {
                    <!-- BEGIN QUICK SIDEBAR TOGGLER -->
                    <li class="dropdown dropdown-extended quick-sidebar-toggler">
                        <span class="sr-only">Toggle Quick Sidebar</span>
                        <i class="icon-speech"></i>
                        <span id="UnreadChatMessageCount" class="badge badge-danger hidden">0</span>
                    </li>
                    <!-- END QUICK SIDEBAR TOGGLER -->
                }
            </ul>
        </div>
    </div>

    @if (AbpSession.MultiTenancySide != MultiTenancySides.Host)
    {
        if (IsGranted(AppPermissions.Pages_Administration_Tenant_SubscriptionManagement) &&
            (Model.LoginInformations.Tenant.IsInTrialPeriod || Model.LoginInformations.Tenant.SubscriptionIsExpiringSoon(Model.SubscriptionExpireNootifyDayCount)))
        {
            <style>
                .page-header-fixed .page-container {
                    margin-top: 100px;
                }

                @@media (max-width: 991px) {
                    .page-header-fixed .page-container {
                        margin-top: 15px !important;
                    }
                }

                @@media (max-width: 767px) {
                    .page-header-fixed .page-container {
                        margin-top: 15px !important;
                    }
                }
            </style>
            <div class="alert subscription-info">
                @if (Model.LoginInformations.Tenant.IsInTrialPeriod && !Model.LoginInformations.Tenant.SubscriptionIsExpiringSoon(Model.SubscriptionExpireNootifyDayCount))
                {
                    @Html.Raw(L("TrialSubscriptionNotification",
                        "<strong>" + Model.LoginInformations.Tenant.Edition.DisplayName + "</strong>",
                        "<a href='" + Url.Action("Buy", "Payment", new {area = "", editionId = Model.LoginInformations.Tenant.Edition.Id, editionPaymentType = EditionPaymentType.BuyNow}) + "'>" + L("ClickHere") + "</a>")
                        )
                }
                @if (Model.LoginInformations.Tenant.SubscriptionIsExpiringSoon(Model.SubscriptionExpireNootifyDayCount))
                {
                    <a href="@Url.Action("Index", "SubscriptionManagement", new {area = "AppAreaName"})">
                        @if (Model.LoginInformations.Tenant.IsInTrialPeriod)
                        {
                            <span><i class="fa fa-exclamation-circle"></i> @L("TrialExpireNotification", Model.LoginInformations.Tenant.GetSubscriptionExpiringDayCount())</span>
                        }
                        else
                        {
                            <span><i class="fa fa-exclamation-circle"></i> @L("SubscriptionExpireNotification", Model.LoginInformations.Tenant.GetSubscriptionExpiringDayCount())</span>
                        }
                    </a>
                }
            </div>
        }
    }
</div>


<script id="linkedAccountsSubMenuTemplate" type="x-tmpl-mustache">
    {{#items}}
    <li>
        <a href="" data-user-id="{{id}}" data-tenant-id="{{tenantId}}" class="recently-linked-user">
            {{shownUserName}}
        </a>
    </li>
    {{/items}}
    {{#hasLinkedUsers}}
    <li class="divider"></li>
    {{/hasLinkedUsers}}
    <li>
        <a href="" id="ManageLinkedAccountsLink">
            <i class="icon-settings"></i> @L("ManageAccounts")
        </a>
    </li>
</script>
<script id="headerNotificationBarTemplate" type="x-tmpl-mustache">
    <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
        <i class="icon-bell"></i>
        {{#unreadCount}}
        <span class="badge badge-danger"> {{unreadCount}} </span>
        {{/unreadCount}}
    </a>
    <ul class="dropdown-menu" id="UserNotificationDropdown">
        <li class="external notifications-header">
            <div class="text-left">
                {{#unreadCount}}
                <a href="" id="setAllNotificationsAsReadLink">@L("SetAllAsRead")</a>
                {{/unreadCount}}
                <a id="openNotificationSettingsModalLink" class="pull-right" href="">@L("Settings")</a>
            </div>
        </li>
        <li>
            <ul class="dropdown-menu-list">
                {{#notifications}}
                <li>
                    <a href="{{url}}" class="user-notification-item {{#url}}user-notification-item-clickable{{/url}} {{#isUnread}}user-notification-item-unread{{/isUnread}}">
                        <span class="details">
                            <i class="{{icon}}"></i> {{text}}
                        </span>
                        <div>
                            <span class="notification-time" title="{{time}}">{{timeAgo}}</span>
                            {{#isUnread}}
                            <span>
                                -
                                <span data-notification-id="{{userNotificationId}}" class="set-as-read-text set-notification-as-read">@L("SetAsRead")</span>
                            </span>
                            {{/isUnread}}
                        </div>
                    </a>
                </li>
                {{/notifications}}
            </ul>
            {{^notifications.length}}
            <div class="notification-empty-text">
                @L("ThereIsNoNotification")
            </div>
            {{/notifications.length}}
        </li>
        {{#notifications.length}}
        <li class="external notifications-footer">
            <div class="text-center"><a href="@Url.Action("Index", "Notifications", new {area = "AppAreaName"})">@L("SeeAllNotifications")</a></div>
        </li>
        {{/notifications.length}}
    </ul>
</script>